﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public class TaxCodeDAO
    {
        DBService _db = null;
        public TaxCodeDAO(string ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }

        public DataTable GetTaxCode()
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from TaxCodes", false, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public TaxCodes GetTaxCode_ByID(int idTaxCode)
        {
            TaxCodes taxCode = new TaxCodes();
            try
            {
                DataTable dt = null;
                dt = _db.ExeSP_DataTable("select * from TaxCodes where IDTaxCodes = @idTaxCode",
                    new string[] { "@idTaxCode" },
                    new object[]{idTaxCode}, CommandType.Text);

                foreach (DataRow dr in dt.Rows)
                {
                    taxCode.IDTaxCodes = idTaxCode;
                    taxCode.TaxCodes1 = dr["TaxCodes"].ToString();
                    taxCode.TaxCodesDescription = dr["TaxCodesDescription"].ToString();
                    taxCode.TaxPercentageRate = float.Parse(dr["TaxPercentageRate"].ToString());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return taxCode;
        }
    }
}
